package com.gtm.controller;

import com.gtm.model.Proposal;
import com.gtm.repository.ProposalRepository;
import com.gtm.repository.UserRepository;
import com.gtm.service.ProposalService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.text.ParseException;

@RestController
@RequestMapping("/proposal")
public class ProposalController {
    @Autowired
    ProposalRepository ppr;

    @Autowired
    ProposalService pps;

    @Autowired
    UserRepository usr;

    @ApiOperation(value="uploadProposal", notes="上传开题报告",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "sid",value = "学生id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "summary",value = "概要",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "keys",value = "关键词",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "references",value = "摘要",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "proposalFile",value = "文件",dataType = "MultipartFile",paramType = "query")
    } )
    @RequestMapping("/uploadProposal/{sid}")
    public Proposal uploadReview(@PathVariable String sid, @RequestParam("summary")String summary,
                                 @RequestParam("keys")String keys, @RequestParam("references")String references,
                                 @RequestParam("proposalFile")MultipartFile reviewFile) throws ParseException, IOException {
        return pps.uploadProposal(sid,summary,keys,references,reviewFile);
    }

    @ApiOperation(value="passProposal", notes="通过报告",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "comment",value = "评论",dataType = "String",paramType = "query")
    } )
    @RequestMapping("/passProposal/{rid}")
    public Proposal passProposal(@PathVariable String rid,@RequestParam("comment") String comment){
        return pps.passProposal(rid,comment);
    }

    @ApiOperation(value="depassProposal", notes="撤销通过",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "comment",value = "评论",dataType = "String",paramType = "query")
    } )
    @RequestMapping("/depassProposal/{rid}")
    public Proposal depassProposal(@PathVariable String rid,@RequestParam("comment") String comment){
        return pps.depassProposal(rid,comment);
    }

    @ApiOperation(value="listBySid", notes="通过学生查找综述",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "sid",value = "学生id",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/listBySid/{sid}")
    public Proposal listBySid(@PathVariable String sid){
        return ppr.findByStuId(sid);
    }

    @ApiOperation(value="findById", notes="通过id查找",httpMethod = "POST")
    @ApiImplicitParams(value ={
            @ApiImplicitParam(name = "rid",value = "id",dataType = "String",paramType = "path")
    } )
    @RequestMapping("/findById/{rid}")
    public Proposal findById(@PathVariable String rid){
        return ppr.findOne(rid);
    }

}
